<div class="popup task-standard-popup" data-relate-id="info">

    <header class="bar bar-nav">
        <a class="button button-link button-nav pull-right close-popup">
            关闭
        </a>
        <h1 class="title">选择积分标准</h1>
    </header>
    <div class="content">
        <div class="content-block" style="padding:0">
            <div class="searchbar row" style="margin:0 .75rem">
                <div class="search-input col-80">
                    <label class="icon icon-search" for="search"></label>
                    <input type="search" id='search' oninput="findStandard.call(this)" placeholder='输入关键字...'/>
                </div>
                <a class="button button-fill button-primary col-20">搜索</a>
            </div>
            {if $taskStandards}
                <div class="list-block standard-block">
                    <ul class="list">
                        {foreach $taskStandards as $v}
                            <li data-names-keyword="{$v['names']}">
                                <a {if $v['names']=="任务执行"}data-default-select="{$v['id']}"{/if} data-names="{$v['names']}" {if $v['acorn'] != 0} data-acorn="{$v['s_acorn']}" {else} data-acorn="0"{/if} class="item-content close-popup{if $v['acorn']<=0} negative{/if}" onclick="selectStandard.call(this,{$v['id']})" data-href="{$url}" data-workload="{$v["workload"]}">
                                    <div class="item-inner" style="min-height:3.6rem;">
                                        <div class="item-name sui-ellipsis-1" style="line-height: 18px;">{$v['names']}</div>
                                        {if $v['s_acorn'] != 0}
                                            <div class="item-src">{$v['acorn']}<i class="icon al-icon al-icon-influence sui-font-size-rem-0-8"></i></div>
                                        {else}
                                            <div class="item-src">不预设</div>
                                        {/if}
                                        <div class="item-src" style="color:#0894ec">选择</div>
                                    </div>
                                </a>
                            </li>
                        {/foreach}
                    </ul>
                </div>
            {else}
                <div class="list" style="margin-top:100px;text-align:center">
                    <img src="{path('[MobileConsoles]/img/null.png')}" alt="" class="" style="width:60%; height:100%;margin:0 20%;display:block;">
                    <div>暂无内容</div>
                </div>
            {/if}
        </div>
    </div>
</div>
<style>

    .standard-block .list > li{
        height:3.6rem;
        line-height:3.6rem;
    }

    .standard-block.list-block{
        margin:.5rem 0;
    }

    .standard-block.list-block ul:before, .standard-block.list-block ul:after{
        display:none;
    }

    .standard-block .item-content .item-name, .standard-block .item-content .item-src{
        line-height:15px; color:#3d4145;
    }

    .standard-block .item-content.negative .item-name, .standard-block .item-content.negative .item-src{
        color:red;
    }

    .standard-block .highlight{
        color:#ff4a2b;
        margin:0;
        font-weight:700;
    }

    .standard-block .item-content.negative .highlight{
        color:#3d4145;
    }

    .selected-standard-show{
        height:3rem;
    }

</style>
<script type="text/javascript">
    function findStandard() {
        var val = $(this).val().toString().replace(/^\s+|\s+$/gm, '');
        var lists = $(".standard-block").find("li[data-names-keyword]");
        if (!val) {
            $(".standard-block").find("li").show();
            for (var i = 0; i < lists.length; i++) {
                var text = $(lists[i]).find(".item-name").text();
                $(lists[i]).find(".item-name").html(text);
            }
            return true;
        }
        for (var i = 0; i < lists.length; i++) {
            var text = $(lists[i]).attr("data-names-keyword");
            var indexOf = text.indexOf(val);
            if (indexOf === -1) {
                $(lists[i]).find(".item-name").html(text);
                $(lists[i]).hide();
                continue;
            }
            var newHtml = "";
            if (indexOf === 0) {
                newHtml = '<span class="highlight">' + val + '<\/span>' + text.substring(val.length);
            }
            if (indexOf > 0) {
                newHtml = text.substring(0, indexOf) + '<span class="highlight">' + val + '<\/span>' + text.substring(val.length + indexOf);
            }
            $(lists[i]).find(".item-name").html(newHtml);
            $(lists[i]).show();
        }
    }


    function selectStandard(id) {
        var names = $(this).attr("data-names");
        var acorn = $(this).attr("data-acorn");
        var workload = $(this).attr("data-workload");
        if (acorn === "0") {
            $(".selected-standard-show").html(names + ":日基础分 &times; 难度系数 &times; 完成质量 &times; 任务量");

            $("#workload_day,#workload_hour,#workload_minute").removeAttr("disabled");
        } else {
            $(".selected-standard-show").text(names + ":" + acorn + "分");
            if (!workload) {
                $("#workload_day,#workload_hour,#workload_minute").removeAttr("disabled");
            } else {
                $("#workload_day,#workload_hour,#workload_minute").attr("disabled", true);
                var workloads = workload.toString().split(",");
                $("#workload_day").val(workloads[0]);
                $("#workload_hour").val(workloads[1]);
                $("#workload_minute").val(workloads[2]);
                $("#workload").val(workload);
            }
        }
        $("[name='standardId']").val(id);
    }

    function selectDefaultStandard() {
        var id = $("[data-default-select]").attr("data-default-select");
        if (id) selectStandard.call($("[data-default-select]"), id);
    }

    function setWorkload() {
        var day = $("#workload_day").val();
        var hour = $("#workload_hour").val();
        var minute = $("#workload_minute").val();
        var workload = [day, hour, minute].join(",");
        $("#workload").val(workload);
    }

</script>
